﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

/// <summary>
/// 位移组件
/// </summary>
public class BlowFlyComponent : ECSMomentCompoentBase
{
    public bool isBlow = false;

    public int blowTime = 0;
    /// <summary>
    /// 位移数据路径
    /// </summary>
    public string blowFlyID;

    /// <summary>
    /// 角色位移施法朝向
    /// </summary>
    public SyncVector3 blowDir=new SyncVector3();
    /// <summary>
    /// 角色位移数据
    /// </summary>
    private ShiftDataGenerate m_blowData;
    public override ECSMomentCompoentBase DeepCopy()
    {
       BlowFlyComponent bfc=new BlowFlyComponent();

       bfc.ID = ID;
       bfc.Frame = Frame;
       bfc.Entity = Entity;

       bfc.isBlow = isBlow;
       bfc.blowFlyID = blowFlyID;
       bfc.blowTime = blowTime;
       bfc.blowDir = blowDir.DeepCopy();

       //此处数据不必从新取
       bfc.BlowData = m_blowData;

       return bfc;
    }
    /// <summary>
    /// 获取位移数据
    /// </summary>
    public ShiftDataGenerate BlowData
    {
        get
        {
            if (m_blowData.Equals(null))
            {
                m_blowData = DataGenerateManager<ShiftDataGenerate>.GetData(blowFlyID);
            }

            return m_blowData;
        }
        set { m_blowData = value; }
    }
    /// <summary>
    /// 设置施法位移朝向
    /// </summary>
    /// <param name="attackerPos">锁定受击坐标</param>
    /// <param name="selfPos">自身施法坐标</param>
    /// <param name="attackDir">施法者朝向</param>
    public void SetBlowFly(Vector3 attackerPos, Vector3 selfPos, Vector3 attackDir)
    {
        Vector3 dir=Vector3.zero;
        ;
        switch (BlowData.m_Direction)
        {
            case DirectionEnum.Forward:
                dir = attackDir;
                break;
            case DirectionEnum.Backward:
                dir = attackDir * (-1);
                break;
            case DirectionEnum.Close://位移时寻找收击者,向受击者位移
                dir = (attackerPos - selfPos);
                dir.y = 0;
                dir = dir.normalized;

                break;
            case DirectionEnum.Leave:// 位移时寻找收击者,向受击者反向位移
                 dir = selfPos - attackerPos;
                dir.y = 0;
                dir = dir.normalized;
                break;
        }

        blowDir.FromVector3(dir);
    }
}

